<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: slider.php 109 2013-09-21 12:07:34Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 109 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 12:07:34 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright © since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	© 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	© 2002-2003 osCommerce - www.oscommerce.com
* 	© 2003     nextcommerce - www.nextcommerce.org
* 	© 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

include('includes/application_top.php');
include('includes/modules/slider/functions.php');
require_once(DIR_FS_INC.'inc.get_url_friendly_text.php');

switch($_GET['save']) {
	case 'new_slider':
		$db->db_query("INSERT INTO ".TABLE_SLIDER." (categories_id, slider_name) VALUES (".$db->db_prepare($_POST['categories_id']).",".$db->db_prepare($_POST['slider_name']).") ");
		$message_stack->add_session('Slider wurde angelegt.<br />Sie können nun Grafiken hinzufügen.', 'success');
		redirect(href_link('slider.php'));
		break;
	
	case 'new_pic':
		saveData();
		redirect(href_link('slider.php'));
		break;
		
	case 'edit':
		saveData('update');
		$message_stack->add_session('Die Änderungen wurden übernommen.', 'success');
		redirect(href_link('slider.php'));
		break;
		
	case 'settings':
		saveSettings();
		$message_stack->add_session('Die Einstellungen wurden gespeichert.', 'success');
		redirect(href_link('slider.php'));
		break;
}

switch($_GET['do']) {
	case 'del_slider':
		deleteSlider();
		redirect(href_link('slider.php', getMenuID('slider')));
		break;

	case 'del_pic':
		deletePic();
		redirect(href_link('slider.php', getMenuID('slider').'&open='.(int)$_GET['slider_id']));
		break;
}

switch($_GET['page']) {
	case 'form':
		include(DIR_WS_MODULES.'slider/form.php');
		break;

	case 'add_pic':
		include(DIR_WS_MODULES.'slider/add_pic.php');
		break;
		
	case 'edit':
		include(DIR_WS_MODULES.'slider/edit.php');
		break;
		
	case 'settings':
		include(DIR_WS_MODULES.'slider/settings.php');
		break;
		
	case 'del_slider':
		include(DIR_WS_MODULES.'slider/del_slider.php');
		break;
}

if(!isset($_GET['page'])) {
	require(DIR_WS_INCLUDES.'metatag.php');
	?>
	</head>
	<body>
	<?php require(DIR_WS_INCLUDES.'header.php'); ?>
	<div id="wrapper">
		<table class="outerTable" cellspacing="0" cellpadding="0">
			<tr>
				<td class="columnLeft2" width="<?php echo BOX_WIDTH; ?>" valign="top">
					<?php require(DIR_WS_INCLUDES.'column_left.php'); ?>
				</td>
				<td class="boxCenter" height="100%" valign="top">
		        	<table class="table_pageHeading" border="0" width="100%" cellspacing="0" cellpadding="0">
			   			<tr>
			     			<td class="pageHeading">Slider</td>
						</tr>
					</table>
					<table width="100%">
						<tr>
							<td>&nbsp;</td>
							<td width="1" align="right"><nobr>
								<a class="slider_button button" onclick="sliderDialog('?page=form', 400, 180, 'Slider anlegen', 'true')" href="#">
									neuen Slider anlegen
								</a> 
								<a class="slider_button button" onclick="sliderDialog('?page=settings', 750, 500, 'Slider Einstellungen', 'true')" href="#">
									Einstellungen
								</a></nobr>
							</td>
						</tr>
					</table><br />
					<table class="dataTable" width="100%">
						<tr class="dataTableHeadingRow">
							<td class="dataTableHeadingContent">Name</td>
							<td class="dataTableHeadingContent">Kategorie</td>
							<td class="dataTableHeadingContent" width="1">Grafiken</td>
							<td class="dataTableHeadingContent" align="right">Aktionen</td>
						</tr>
						<?php
						$slider = $db->db_query("SELECT
													slider_id,
													categories_id,
													slider_name
												FROM
													".TABLE_SLIDER."
												ORDER BY
													slider_id");
						if($slider->_numOfRows) {
							while(!$slider->EOF) {
								$img = $db->db_query("SELECT
															COUNT(image_id) AS total
														FROM
															".TABLE_SLIDER_IMAGES."
														WHERE
															slider_id = ".$db->db_prepare($slider->fields['slider_id'])."
														AND
															language_id = '".(int)$_SESSION['languages_id']."' ");
								
								echo '	<tr>';
								echo '		<td>'.$slider->fields['slider_name'].'</td>';
								echo '		<td>'.get_categories_name($slider->fields['categories_id'], $_SESSION['languages_id']).'</td>';
								echo '		<td align="center">'.$img->fields['total'].'</td>';
								echo '		<td width="1"><nobr>
												<a class="slider_button button" onclick="sliderDialog(\'?page=add_pic&slider_id='.$slider->fields['slider_id'].'\', 500, 290, \'Grafik hinzufügen\',\'true\')" href="#">
													Grafik hinzufügen
												</a> 
												<a class="slider_button button" onclick="sliderDialog(\'?page=edit&slider_id='.$slider->fields['slider_id'].'\', 700, 400, \'Slider - '.$slider->fields['slider_name'].' - bearbeiten\', \'true\')" href="#">
													bearbeiten
												</a> 
												<a class="slider_button button" onclick="sliderDialog(\'?page=del_slider&slider_id='.$slider->fields['slider_id'].'\', 520, 210, \'Slider löschen\')" href="#">
													löschen
												</a></nobr>
											</td>';
								echo '	</tr>';
								$slider->MoveNext();
							}
						} else
							echo '	<tr><td align="center" colspan="4"><em>noch keine Slider vorhanden</em></td></tr>';
						?>
					</table>
			    </td>
			</tr>
		</table>
	</div>
	<script type="text/javascript">
		function sliderDialog(url, w, h, title, save) {
			if(save == 'true') {
				var extra_button = {"Speichern":function(){$("#slider").submit();},"Abbruch": function() {$(this).dialog("close");}};
			} else {
				var extra_button = '';
			}
			$('#dialog_box').dialog({
				autoOpen:false,
				show:"fade",
				hide:"explode",
				width:w,
				height: h,
				buttons: extra_button,
				modal:true,
				position:['center','center']
			});
			
			$("#dialog_box").load(url).dialog("open");
			if(title !=''){$('.ui-dialog-title').html(title);}
			return false;
		}
		<?php if(isset($_GET['open'])) { ?>
			$(function(){
				sliderDialog('?page=edit&slider_id=<?php echo $_GET['open'] ?>', 700, 400, 'Slider - bearbeiten', 'true');
			});
		<?php } ?>
	</script>
	<div title="Slider" id="dialog_box" style="display:none"></div>
	<?php require(DIR_WS_INCLUDES.'footer.php'); ?>
	</body>
	</html>
	<?php require(DIR_WS_INCLUDES.'application_bottom.php');
}